from django.shortcuts import render, HttpResponse, redirect
from django.http import JsonResponse


def chart_list(request):
    """数据统计的页面"""
    return render(request, "chart_list.html")


def chart_bar(request):
    """构造柱状图的数据"""
    # 从数据库中来进行获取数据
    legend = ['月份', "人员"]
    x_axis = ['一月', '二月', '三月', '四月', '五月', '六月']
    series_list = [
        {
            "name": '销量',
            "type": 'bar',
            "data": [5, 20, 36, 10, 10, 20]
        },
        {
            "name": '薪资',
            "type": 'line',
            "data": [25, 23, 86, 12, 11, 27]
        }
    ]
    result = {
        "status": True,
        "data": {
            "legend": legend,
            "series_list": series_list,
            "x_axis": x_axis,
        }
    }
    return JsonResponse(result)

def chart_pie(request):
    """饼状图"""
    db_data_list=[
    {"value": 2048, "name": '北京'},
    {"value": 735, "name": '上海'},
    {"value": 1580, "name": '杭州'},
    ]
    result = {
        "status": True,
        "data": db_data_list
    }
    return JsonResponse(result)
def chart_line(request):
    """折线图"""
    legend = ['Email', 'Union Ads']
    x_axis = ['一月', '二月', '三月', '四月', '五月', '六月']
    series_list = [
        {
            "name": '销量',
            "type": 'line',
            "data": [2250, 2569, 4400, 1465, 3480, 2870, 3140]
        },
        {
            "name": '人员',
            "type": 'line',
            "data": [5200, 6770, 12101, 3477, 9043, 6770, 8909]
        }
    ]
    result = {
        "status": True,
        "data": {
            "legend": legend,
            "series_list": series_list,
            "x_axis": x_axis,
        }
    }
    return JsonResponse(result)


